using System;
using System.Collections.Generic;

using Sce.Pss.Core;
using Sce.Pss.Core.Environment;
using Sce.Pss.Core.Graphics;
//using Sce.Pss.Core.Input;
using CResourceManager;
using ResourceManager;
using Business;
using Sce.Pss.Core.Imaging;

namespace ExampleResManager
{
	public class AppMain
	{
		private static GraphicsContext graphics;
		private static DrawProvider _drawProvider;
		
		public static void Main (string[] args)
		{
			Initialize ();

			while (true) {
				SystemEvents.CheckEvents ();
				Update ();
				Render ();
			}
		}
		
		public static void Initialize ()
		{
			// Set up the graphics system
			graphics = new GraphicsContext ();
			
			//Set up Res manager
			Library.Instance.Init(graphics);
			
			_drawProvider = new DrawProvider(graphics);
			
			// init storage
			if(!Storage.Exist("textText.txt"))
			{
				Storage.SaveFile("textText.txt","This is SPARTA!!!");
			}
			
			RegAccess.SetValue("TestKey","TestValue");
			
			string val = RegAccess.ReadValue("TestKey");
			RegAccess.SetValue("TestKey", "NewValue");
		}

		public static void Update ()
		{
			// Query gamepad for current state
			//var gamePadData = GamePad.GetData (0);
		}

		public static void Render ()
		{
			// Clear the screen
			graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f);
			graphics.Clear ();
			
			Sprite srite = Library.Instance.GetSprite("/Application/Resources/Images/Backgrounds/2d_1.png");
			
			_drawProvider.DrawSprite(srite);
			
			
			string text = Storage.ReadFile("textText.txt");
			var font = new Font(FontAlias.System, 24, FontStyle.Regular);
			_drawProvider.DrawText(text, 0xffff0000, font, _drawProvider.Width/2-50, _drawProvider.Height/2);
						
			//CDraw.AddSprite(
			// Present the screen
			graphics.SwapBuffers ();
		}
		
		static void Term()
    	{
        	CDraw.Term();
			Library.Instance.Dispose();
        	graphics.Dispose();
    	}
	}
}
